/*
 *
 *   This file is part of jSevenBar. Copyright 2011 Alex Volodko
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 */
package de.xhelp.jsevenbar.core;

import java.awt.Component;

/**
 * This class deal with grouped tabs
 * @author Alex Volodko
 * 
 */
public class Tabs {
	private final int hwnd;

	public Tabs(int hwnd) {
		this.hwnd = hwnd;
	}

	private static native int registerTab(int tabHwnd, int mainHwnd);
	private static native int unregisterTab(int tabHwnd);
	private static native int setTabActive(int tabHwnd, int mainHwnd);

	/**
	 * Group the component with the main window
	 * 
	 * @param component
	 *            New tab windows
	 */
	public void addTab(Component component) {
		int tabHwnd = JSevenBar.getHandle(component);
		int result = registerTab(tabHwnd, hwnd);
		if (result != JSevenBar.S_OK) {
			throw new IllegalStateException("Return code: " + result);
		}
	}

	/**
	 * Remove tab from the group. <br>
	 * <b>Note:</b> Taskbar entry of the tab (if exist) will not been removed.
	 * This method will just separete the window from the group.
	 * 
	 * @param component
	 */
	public void removeTab(Component component) {
		int tabHwnd = JSevenBar.getHandle(component);
		int result = unregisterTab(tabHwnd);
		if (result != JSevenBar.S_OK) {
			throw new IllegalStateException("Return code: " + result);
		}
	}
	
	/**
	 * Mark the tab in the group as active
	 * @param component
	 */
	public void setActiveTab(Component component) {
		int tabHwnd = JSevenBar.getHandle(component);
		int result = setTabActive(tabHwnd, hwnd);
		if (result != JSevenBar.S_OK) {
			throw new IllegalStateException("Return code: "+result);
		}
	}
}
